﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Reflection;
using System.Diagnostics;
using System.DirectoryServices.AccountManagement;

namespace CMD_DKT.Utilities
{
    class CMDInfo
    {
        public static ArrayList GetCMDInfo(Boolean Enviado)
        {
            ArrayList info= new ArrayList();
            Assembly assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            string usrMail = UserPrincipal.Current.DisplayName;
            DateTime date = DateTime.Today;
            string format = "yyyy/MM/dd HH:mm:ss";
            string fechaEnvio = date.ToString(format);

            //string docInfo_unidDocInfo= "-1";
            string[] docInfo_fechaEnvio = { "docInfo_fechaEnvio", fechaEnvio };
            string[] docInfo_wUsr = {"docInfo_wUsr",Environment.UserName};
            string[] docInfo_pcname = {"docInfo_pcname", Environment.UserDomainName};
            string[] docInfo_dktVersion = {"docInfo_dktVersion",fvi.ProductVersion.Replace(".","")};
            string[] docInfo_userUltimo = { "docInfo_userUltimo", Environment.UserName };
            string[] docInfo_wUsrMail = {"docInfo_wUsrMail","jasalaza@mail.com"};

            if(Enviado)
                info.Add(docInfo_fechaEnvio);
            info.Add(docInfo_wUsr);
            info.Add(docInfo_pcname);
            info.Add(docInfo_dktVersion);
            info.Add(docInfo_userUltimo);
            info.Add(docInfo_wUsrMail);


            return info;
        }

        // por probar
        public static string GetADUserEmailAddress(string username)
        {
            using (var pctx = new PrincipalContext(ContextType.Domain))
            {
                using (UserPrincipal up = UserPrincipal.FindByIdentity(pctx, username))
                {
                    return up != null && !String.IsNullOrEmpty(up.EmailAddress) ? up.EmailAddress : string.Empty;
                }

            }

        }// GetADUserEmailAddress

    }// end class
}
